//
//  LYDataSourceManager.m
//  artist
//
//  Created by Jay_Apple on 16/4/15.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYDataSourceManager.h"
#import "LYMineHeaderModel.h"
#import "LYMineHeaderItemModel.h"
#import "LYCityDataDBTool.h"
#import "LYIntoductionModel.h"


#define TYPE self.type

@interface LYDataSourceManager ()

@property (nonatomic, strong, readwrite) LYUserInfoModel *userInfo;

@property (nonatomic, assign, readwrite) roleType type;

@property (nonatomic, strong, readwrite) LYLoginInfoModel *loginInfo;

@property (nonatomic, strong, readwrite) LYLocationInfo *locationInfo;

@end

static id _instance;

@implementation LYDataSourceManager

#pragma mark - 构建单例

+ (instancetype)allocWithZone:(struct _NSZone *)zone{
    
    if (_instance == nil) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _instance = [super allocWithZone:zone];
        });
    }
    return _instance;
}

+ (instancetype)sharedManager{
    
    
    if (_instance == nil) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _instance = [[self alloc] init];
        });
    }
    return _instance;
    
}


- (id)copyWithZone:(NSZone *)zone
{
    return _instance;
}

#pragma mark - 重写方法
- (LYUserInfoModel *)userInfo{

    if ([VVYCheckStatus sharedInstance].isLogin) {
        if (_userInfo == nil) {
            _userInfo = [VVYSaveDataManager getDataWithKey:KEY_USERMESSAGE];

        }
    }else{
    
        _userInfo = nil;
    }
    
    return _userInfo;

}

- (roleType)type{

    if (self.userInfo) {
        return self.userInfo.role_id;
    }else{
    
        return 0;
    }
}

- (LYLoginInfoModel *)loginInfo{


    if ([VVYCheckStatus sharedInstance].isLogin) {
        if (_loginInfo == nil) {
            _loginInfo = [VVYSaveDataManager getDataWithKey:LYUserLoginInfo];
        }
    }else{
        
        _loginInfo = nil;

    }
    
    return _loginInfo;


}
#pragma mark - 数据源方法


/**
 *  发布按钮
 */
- (UIImage *)getPublishBtnImage{
    
    
    switch (TYPE) {
        case roleTypeStu:
            
            return [UIImage imageNamed:@"艺友圈未选中"];
            
            break;
        default:
            
            return [UIImage imageNamed:@"发布未选中"];
            
            break;
    }
    
}

- (UIImage *)getPublishBtnHighlightImage{
    
    
    switch (TYPE) {
        case roleTypeStu:
            
            return [UIImage imageNamed:@"艺友圈选中"];
            
            break;
        default:
            
            return [UIImage imageNamed:@"发布选择"];
            
            break;
    }
    
    
}

/**
 *  首页rightItem
 */
- (UIImage *)getHomeRightItemImage{
    
    
    switch (TYPE) {
        case roleTypeStu:
            
            return [UIImage imageNamed:@"发帖"];
            
            break;
        default:
            
            return [UIImage imageNamed:@"信息"];
            
            break;
    }
    
}

/**
 *  我的页面背景图
 */
- (UIImage *)getMineHeaderBGImage{
    
    
    switch (TYPE) {
        case roleTypeStu:
            return [UIImage imageNamed:@"bg_student"];
            break;
            
        case roleTypeTeacher:
            return [UIImage imageNamed:@"bg_teacher"];
            break;
        case roleTypeOrz:
            return [UIImage imageNamed:@"bg_orz"];
            break;
        default:
            return [UIImage imageNamed:@"bg_student"];
            break;
    }
    
}

/**
 *  我的头部Items
 */
- (NSArray <LYMineHeaderItemModel *>*)getMineHeaderItems{
    
    LYMineHeaderItemModel *order = [[LYMineHeaderItemModel alloc] init];
    order.image = @"订单";
    order.title = @"订单";
    order.className = @"LYMineOrderViewController";
    
    LYMineHeaderItemModel *Integration = [[LYMineHeaderItemModel alloc] init];
    Integration.image = @"积分";
    Integration.title = @"积分";
    Integration.className = @"LYIntegrationViewController";
    
    LYMineHeaderItemModel *money = [[LYMineHeaderItemModel alloc] init];
    money.image = @"钱包";
    money.title = @"钱包";
    money.className = @"LYMoneyViewController";
    
    LYMineHeaderItemModel *CA = [[LYMineHeaderItemModel alloc] init];
    CA.image = @"认证";
    CA.title = @"认证";
    CA.className = @"LYStudentDataViewController";
    
    
    switch (TYPE) {
        case roleTypeStu:
            
            return @[
                     order,
                     Integration
                     ];
            break;
            
        default:
            
            return @[
                     money,
                     CA
                     ];
            
            break;
    }
}

/**
 *  我的header模型
 */
- (LYMineHeaderModel *)getMineHeaderModel{

    LYMineHeaderModel *model = [[LYMineHeaderModel alloc] init];
    if ([VVYCheckStatus sharedInstance].isLogin) {
        model.userName = self.loginInfo.nick_name;
        model.phone = self.loginInfo.username;
        model.icon = self.loginInfo.head_pic;
        model.mode = loginModeLoginIn;
    }else{
    
        model.mode = loginModeLoginOut;
    
    }
    model.items = [self getMineHeaderItems];
    model.bgImageName = [self getMineHeaderBGImage];
    
    return model;
}

/**
 *  我的页面列表plist
 */
- (NSString *)getMineListName{

    switch (TYPE) {
        case roleTypeStu:
            return @"mine_stu.plist";
            break;
            
        case roleTypeTeacher:
            return @"mine_tea.plist";
            break;
        case roleTypeOrz:
            return @"mine_orz.plist";
            break;
        default:
            return @"mine_stu.plist";
            break;
    }

}

/**
 *  我的简介
 */
- (NSArray <LYIntoductionModel *> *)getIntroductionModels{


    LYIntoductionModel *model1 = [[LYIntoductionModel alloc] init];
    model1.title = @"个人简介";
    model1.placeHolder = @"请输入个人简介";
    
    LYIntoductionModel *model2 = [[LYIntoductionModel alloc] init];
    model2.title = @"个人成就";
    model2.placeHolder = @"请输入个人成就";
    
    LYIntoductionModel *model3 = [[LYIntoductionModel alloc] init];
    model3.title = @"教学理念";
    model3.placeHolder = @"请输入教学理念";
    
    LYIntoductionModel *model4 = [[LYIntoductionModel alloc] init];
    model4.title = @"机构简介";
    model4.placeHolder = @"请输入机构简介";
    
    LYIntoductionModel *model5 = [[LYIntoductionModel alloc] init];
    model5.title = @"机构成就";
    model5.placeHolder = @"请输入机构成就";
    
    switch (TYPE) {
        case roleTypeTeacher:
    
            return @[model1, model2, model3];
            
            break;
            
        case roleTypeOrz:
            
            return @[model4, model5, model3];
            
            break;
            
        default:
            break;
    }
    
    return nil;

}



/**
 *  定位信息
 */
- (void)setUpLocationInfo{

    
    LYLocationInfo *locationInfo = [[LYLocationInfo alloc] init];
    
    NSString *city = [VVYLocationManager sharedManager].city;
    CLLocationCoordinate2D coordinate = [VVYLocationManager sharedManager].locCoordinate;
    NSInteger city_id = [LYCityDataDBTool getIDWithName:city];
    
    locationInfo.locationCity = city;
    
    locationInfo.lat = [NSString stringWithFormat:@"%f",coordinate.latitude];
    locationInfo.lng = [NSString stringWithFormat:@"%f", coordinate.longitude];
    
    locationInfo.city_id = [NSString stringWithFormat:@"%zd",city_id];
    
    self.locationInfo = locationInfo;
    
    
}

/**
 *  获取收藏列表模型
 */
- (Class)getCollectListClassWithType:(ObjectType)type{

    NSString *classStr = nil;
    
    switch (type) {
        case ObjectTypePost:
            
            classStr = @"LYPostDetailModel";
            
            break;
            
        case ObjectTypeClass:
            
            classStr = @"LYMyClassListModel";
            break;
            
            case ObjectTypeVideo:
            classStr = @"LYMyVideoListModel";
            
            break;
    }
    
    return NSClassFromString(classStr);

}

/**
 *  重置用户信息
 */
- (void)resetUserInfo{

    self.userInfo = nil;
    self.loginInfo = nil;

}

@end
